import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin'
//fetch获取广告数据
import {getAdData} from '../../../fetch/home/home.js';
import HomeAd from '../../../components/HomeAd/index.jsx';
class Ad extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
        this.state={
        	adData:[]
        }
    }
    render() {
        return (
        	<div>
        		 <HomeAd data={this.state.adData} />
        	</div>
           
        )
    }
    componentDidMount() {
    	//请求数据;
    	let result = getAdData();
        //console.log(result) Promise对象
    	result.then((res)=>{
    		return res.json()
    	}).then((json)=>{
    		//console.log(json) [{},{},{},{},{},{}]
    		let adData = json
    		if(adData.length){
    			this.setState({
    				adData:adData
    			});
    		}
    	})
    }
}

// 使用 require.ensure 异步加载，还不支持 ES6 的 export 
// export default NotFound
module.exports = Ad